using System;
using System.Collections.Generic;
using FireStarter.Base;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using FireStarter.CodeGeneration.Parser;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Templates
{
    [TestFixture]
    public class TestTemplates : TestBase
    {
        /// <summary>
        /// THIS IS NOT A TEST.
        /// ----------------------
        /// This provides a way to test your new template without creating a permanent test.
        /// Simply adapt the test and its models for your example.
        /// It will popup your output code in a window, or show you the errors.
        /// </summary>
        [Test, Ignore("Just a utility method to test templates as you create them.")]
        public void Test_GenericTemplate()
        {
            //---------------Set up test pack-------------------
            string template = FireStarter.CodeGeneration.Templates.Test_BO_TestUtilsBO;

            IList<IModelClass> modelClasses = new List<IModelClass>();

            DMSolution modelProject = new DMSolution();
            modelProject.BOProjectName = "TestProject.BO";
            modelProject.BOTestProjectName = "TestProject.Test.BO";
            DMAssembly modelAssembly = new DMAssembly(modelProject.BOProjectName);
            modelProject.Assemblies.Add(modelAssembly);
            foreach (IModelClass modelClass in modelClasses)
            {
                modelAssembly.Classes.Add((DMClass)modelClass);
            }
            
            

            IModelClass dmClass = new DMClass();
            dmClass.ClassName = "TestClass";
            TestUtilsCodeGen.CreatePropertyOnClass((DMClass) dmClass, "TestProperty", "Decimal");
            IModelProperty toClass = TestUtilsCodeGen.CreatePropertyOnClass((DMClass) dmClass, "TestProperty2", "String");
            //toClass.IsCompulsory = true;
            TestUtilsCodeGen.CreatePropertyOnClass((DMClass) dmClass, "TestProperty3", "Int32");
            modelAssembly.Classes.Add((DMClass) dmClass);


            ModelStrategyMapper modelStrategyMapper = new ModelStrategyMapper();
            modelStrategyMapper.SetStrategy(typeof(IModelElement), new ReflectionGenerationStrategy());
            //-------------Assert Preconditions -------------

            //---------------Execute Test ----------------------
            StatementParser statementParser = new StatementParser();
            TemplateExpression templateExpression = statementParser.Parse(ref template);
            try
            {
                string generatedTemplate = templateExpression.Generate(modelStrategyMapper, dmClass);
                TestUtilsCodeGen.ShowCodeInForm(generatedTemplate);
            }
            catch(Exception ex)
            {
                TestUtilsCodeGen.ShowCodeInForm("ERROR:" + Environment.NewLine + ex.Message);
            }
            //---------------Test Result -----------------------
            //This is not a test.
        }

        
        //[Test, Ignore("Just a utility method to test templates as you create them.")]
        //public void Test_GenericTemplate()
        //{
        //    //---------------Set up test pack-------------------
        //    string template = FireStarter.CodeGeneration.Templates.Test_BO_TestUtils;

        //    IList<IModelClass> modelClasses = new List<IModelClass>();

        //    IModelSolution modelProject = new IModelSolution();
        //    modelProject.ModelClasses = modelClasses;
        //    modelProject.BOProjectName = "TestProject.BO";
        //    modelProject.ProjectName = "TestProject.Test.BO";

        //    DMClass dmClass = new DMClass();
        //    dmClass.ClassName = "TestClass";
        //    dmClass.Parent = modelProject;
        //    IModelProperty modelProperty = (IModelProperty)TestUtilsCodeGen.CreatePropertyOnClass(dmClass, "TestProperty");
        //    //modelProperty.DefaultValue = "hello world";
        //    modelProperty.PropertyType.PropertyTypeName = "Decimal";
        //    modelProperty.PropertyType.AssemblyName = "System";
        //    modelProperty.LookupListType = ModelLookupType.BusinessObject;
        //    modelProject.ModelClasses.Add(dmClass);


        //    ModelStrategyMapper modelStrategyMapper = new ModelStrategyMapper();
        //    modelStrategyMapper.SetStrategy(typeof(IModelElement), new ReflectionGenerationStrategy());
        //    //-------------Assert Preconditions -------------

        //    //---------------Execute Test ----------------------
        //    StatementParser statementParser = new StatementParser();
        //    TemplateExpression templateExpression = statementParser.Parse(ref template);
        //    try
        //    {
        //        string generatedTemplate = templateExpression.Generate(modelStrategyMapper, modelProject);
        //        TestUtilsCodeGen.ShowCodeInForm(generatedTemplate);
        //    }
        //    catch (Exception ex)
        //    {
        //        TestUtilsCodeGen.ShowCodeInForm("ERROR:" + Environment.NewLine + ex.Message);
        //    }
        //    //---------------Test Result -----------------------
        //    //This is not a test.
        //}

        
    }
}
